<template>
    <h2>添加门店页面</h2>
    <table border="1">
        <tr>
            <td>门店名称</td>
            <td>
                <input type="text" placeholder="请输入门店名称"v-model="info.sName">
            </td>
        </tr>
        <tr>
            <td>门店地址</td>
            <td>
                <input type="text" v-model="info.address"placeholder="请输入门店地址">
            </td>
        </tr>
        <tr>
            <td>门店图片</td>
            <td>
                <img :src="info.img" style="width: 100px;height: 70px;">
                <input type="file" @change="Upload">
            </td>
        </tr>
        <tr>
            <td>门店服务</td>
            <td>
                <select v-model="info.vid">
                    <option :value="-1">请选择</option>
                    <option v-for="item in Server" :value="item.vid">{{item.vName}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>门店状态</td>
            <td>
                <input type="radio" :value="true"v-model="info.state">启用
                <input type="radio" :value="false"v-model="info.state">禁用
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加门店" @click="Add">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { server } from 'typescript';
import { ref ,onMounted} from 'vue';
import { useRouter } from 'vue-router';
const rour=useRouter();
onMounted(()=>{
    Bind();
})
//绑定下拉框
const Server=ref([{
    "vid": 0,
    "vName": "string"
}])
const Bind=()=>{
    axios.get("https://localhost:7218/api/Shops/ShowServer")
    .then(res=>{
        Server.value=res.data
    })
}
const info=ref({
    "sid": 0,
  "sName": "",
  "address": "",
  "img": "",
  "vid": -1,
  "state": true,
  "isdel": 0
})
const Add=()=>{
    if(info.value.sName==""){
        alert("门店名称不能为空");
        return;
    }
axios.post("https://localhost:7218/api/Shops/Addshops",info.value)
.then(res=>{
    if(res.data>0){
        alert("添加成功");
        rour.push("Showshop")
    }
    else{
        alert("添加失败");
    }
})
}
const Upload=(E:any)=>{
var file=E.target.files[0]
var fd=new FormData()
fd.append("file",file)
axios.post("https://localhost:7218/api/Upload",fd)
.then(res=>{
  info.value.img=res.data
})
}
</script>